<template>
  <div class="main" v-loading="isLoading">
    <div class="ring" v-if="!isReg">
      <i style="--clr:#00ff0a;"></i>
      <i style="--clr:#ff0057;"></i>
      <i style="--clr:#fffd44;"></i>
      <div class="login">
        <img src="@/assets/image/logo.png" alt="">
        <div class="inputBx">
          <input type="text" v-model="formLogin.phone" placeholder="手机号">
        </div>
        <div class="inputBx">
          <input type="password" v-model="formLogin.password" placeholder="密码">
        </div>
        <div class="inputBx">
          <input type="submit" @click="submitLogin" value="Sign in">
        </div>
        <div class="links">
          <a href="javascript:void (0)" @click="isReg=true">去注册</a>
        </div>
      </div>
    </div>
    <div class="ring ring1" v-else>
      <i style="--clr:#00ff0a;"></i>
      <i style="--clr:#ff0057;"></i>
      <i style="--clr:#fffd44;"></i>
      <div class="login">
        <img src="@/assets/image/logo.png" alt="">
        <el-upload
            class="avatar-uploaders"
            action="https://jsonplaceholder.typicode.com/posts/"
            :show-file-list="false"
            :http-request="beforeAvatarUpload"
            >
          <img v-if="imageUrl" :src="imageUrl" class="uploadAvatar">
          <i v-else class="el-icon-picture-outline avatar-uploader-icon"></i>
        </el-upload>
        <div class="inputBx">
          <input type="text" v-model="form.phone" placeholder="联系电话">
        </div>
        <div class="inputBx">
          <input type="password" v-model="form.password" placeholder="密码">
        </div>
        <div class="inputBx">
          <el-radio-group v-model="form.gender">
            <el-radio style="margin-left: 30px;color: #fff" label="M">男</el-radio>
            <el-radio style="margin-left: 30px;color: #fff" label="F">女</el-radio>
          </el-radio-group>
        </div>
        <div class="inputBx">
          <el-date-picker type="date" placeholder="你的生日" v-model="form.birthday" style="width: 100%;"></el-date-picker>
        </div>
        <div class="inputBx">
          <input type="text" v-model="form.remake" placeholder="居住地址">
        </div>
        <div class="inputBx">
          <input type="text" v-model="form.realName" placeholder="姓名">
        </div>
        <div class="inputBx">
          <input type="text" v-model="form.idCard" placeholder="身份证号">
        </div>
        <div class="inputBx">
          <input type="text" v-model="form.habits" placeholder="兴趣爱好">
        </div>
        <div class="inputBx">
          <input type="text" v-model="form.note" placeholder="月薪">
        </div>
        <div class="inputBx">
          <input type="submit" @click="submitReg" value="Sign in">
        </div>
        <div class="links">
          <a href="javascript:void (0)" @click="isReg=false">去登录</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import {uploadFile} from "@/api/apiFox";

  export default {
    data(){
      return{
        formLogin:{
          password: "",
          phone: "",
        },
        imageUrl:"",
        form:{
          birthday: "",
          note:"",//月薪
          gender: "M",
          habits: "",
          role:2,
          realName:"",
          icon: "",
          idCard: "",
          password: "",
          phone: "",
          username: "",
          remake:""
        },
        isLoading:false,
        isReg:false
      }
    },
    methods:{
      clear(){
        for(let key  in this.form){
          this.form[key] = ""
        }
        for(let key  in this.formLogin){
          this.formLogin[key] = ""
        }
        this.form.role = 2
      },

      beforeAvatarUpload(file) {
        uploadFile(file).then(res=>{
          console.log(res)
          this.form.icon = res.data
          this.imageUrl=res.data
        }).catch(err=>{})
      },


      submitReg(){
        this.isLoading=true
        this.form.username = this.form.phone
        this.form.birthday =  Date.parse(this.form.birthday)
        this.$store.dispatch('registertSet',this.form).then(res=>{
          this.$message.success('注册成功')
          this.isLoading=false
          this.clear()
          this.$router.push('/forum')
        }).catch(err=>{ this.isLoading=false})
      },

      submitLogin(){
        this.isLoading=true
        this.$store.dispatch('loginSetToken',this.formLogin).then(res=>{
          console.log(res)
          this.isLoading=false
          this.clear()
          this.$message.success('登录成功')
          this.$router.push('/forum')
        }).catch(err=>{
          this.isLoading=false
        })
      }
    },
    mounted() {

    }
  }
</script>

<style scoped lang="scss">
.avatar-uploaders{
  width: 150px;
  height: 150px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  border: 1px dashed #d9d9d9;
  position: absolute;
  left: -200px;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 150px;
  height: 150px;
  line-height: 150px;
  text-align: center;
}
.uploadAvatar {
  width: 150px;
  height: 150px;
  display: block;
  border-radius: 50%;
}
.main{
  width: 100%;
  min-height: 100vh;
  background: #771026;
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}
@import url("https://fonts.googleapis.com/css2?family=Quicksand:wght@300&display=swap");
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Quicksand", sans-serif;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #111;
  width: 100%;
  overflow: hidden;
}
.ring {
  position: relative;
  width: 500px;
  height: 500px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.ring1{
  width: 800px;
  height: 800px;
}
.ring i {
  position: absolute;
  inset: 0;
  border: 2px solid #fff;
  transition: 0.5s;
}
.ring i:nth-child(1) {
  border-radius: 38% 62% 63% 37% / 41% 44% 56% 59%;
  animation: animate 6s linear infinite;
}
.ring i:nth-child(2) {
  border-radius: 41% 44% 56% 59%/38% 62% 63% 37%;
  animation: animate 4s linear infinite;
}
.ring i:nth-child(3) {
  border-radius: 41% 44% 56% 59%/38% 62% 63% 37%;
  animation: animate2 10s linear infinite;
}
.ring:hover i {
  border: 6px solid var(--clr);
  filter: drop-shadow(0 0 20px var(--clr));
}
@keyframes animate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
@keyframes animate2 {
  0% {
    transform: rotate(360deg);
  }
  100% {
    transform: rotate(0deg);
  }
}
.login {
  position: absolute;
  width: 300px;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 20px;
}
.login h2 {
  font-size: 2em;
  color: #fff;
}
.login .inputBx {
  position: relative;
  width: 100%;
}
.login .inputBx input {
  position: relative;
  width: 100%;
  padding: 12px 20px;
  background: transparent;
  border: 2px solid #fff;
  border-radius: 40px;
  font-size: 1.2em;
  color: #fff;
  box-shadow: none;
  outline: none;
}
.login .inputBx input[type="submit"] {
  width: 100%;
  background: #0078ff;
  background: linear-gradient(45deg, #ff357a, #fff172);
  border: none;
  cursor: pointer;
}
.login .inputBx input::placeholder {
  color: rgba(255, 255, 255, 0.75);
}
.login .links {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.login .links a {
  color: #fff;
  text-decoration: none;
}

</style>
